<?php

include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';


class Refactoring_Audio_Tag extends Answer_Patterns {
   public function start($domDocument) {
      $result = "";

      $search = $domDocument->getElementsByTagName('embed');
      
      foreach ($search as $f) {
       
         if (ereg("^(.*).mid$", strtolower($f->getAttribute('src'))) || ereg("^(.*).mp3$", strtolower($f->getAttribute('src')))) {
            $answer = '&LT;audio '
                    . 'src="' . $f->getAttribute('src') . '" '
                    . 'controls="true" '. ( $f->getAttribute('autostart') == 'true' ? 'autoplay="true"' : 'autoplay="false"') .' /&GT;';

            $mount_tree = new Mount_DOM_tree();
            $result .= parent::elementAnswerPatterns("&LT;embed&GT;", $f->getLineNo(), "&LT;audio/&GT;");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $answer);
         }
      }

      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Modificar a estrutura de audio") . $result;
      }

      return $result;
   }
}